﻿

function add(x,y) {
    return x + y;
}

function mult(x, y) {
    return x * y;
}

this.onmessage = function (event) {
    var msg = event.data;
    var arr = msg.split('_');

    var char = arr[0];
    var num1 = parseInt(arr[1]);
    var num2 = parseInt(arr[2]);

    switch(char){
        case "add":
            postMessage(add(num1, num2));
            break;
        case "mult":
            postMessage(mult(num1, num2));
            break;
    }
}